package com.uuticketweb.ticket.flight.action;

import java.util.List;

import com.googlecode.jsonplugin.annotations.SMDMethod;
import com.opensymphony.xwork2.ActionSupport;
import com.uuticketweb.ticket.flight.service.FlightService;
import com.uuticketweb.ticket.flight.service.factory.FlightServiceFactory;
import com.uuticketweb.ticket.pojos.ThreeCode;

public class QueryAirportAction extends ActionSupport{
	
	private AirportJson[] airports;

	public String execute() {
		airports = getAirports();
		return INPUT;
	}
	
	@SMDMethod
	public AirportJson[] getAirports() {
		FlightService flightService = FlightServiceFactory.getFlightService();
		List airportList = flightService.getAirportOfCountry("JPN");
		AirportJson[] ap = new AirportJson[airportList.size()];
		for(int i = 0; i < airportList.size(); i ++) {
			ThreeCode threeCode = (ThreeCode)airportList.get(i);
			ap[i] = new AirportJson(threeCode.getAirportThreeCode(), threeCode.getAirportChineseName(), 
					threeCode.getAirportEnglishName(), threeCode.getCountryCode());
		}
		return ap;
	}
	
	public class AirportJson {
		private String code;
		private String city;
		private String cityEngName;
		private String country;
		
		
		
		public AirportJson(String code, String city, String cityEngName,
				String country) {
			super();
			this.code = (code == null ? "" : code);
			this.city = (city == null ? "" : city);
			this.cityEngName = (cityEngName == null ? "" : cityEngName);
			this.country = (country == null ? "" : country);
		}
		public String getCode() {
			return code;
		}
		public void setCode(String code) {
			this.code = code;
		}
		public String getCity() {
			return city;
		}
		public void setCity(String city) {
			this.city = city;
		}
		public String getCityEngName() {
			return cityEngName;
		}
		public void setCityEngName(String cityEngName) {
			this.cityEngName = cityEngName;
		}
		public String getCountry() {
			return country;
		}
		public void setCountry(String country) {
			this.country = country;
		}
		
		
	}
}
